package m4;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

/**
 * @Author wy
 * @Date 2021/3/2 15:25
 * @Version 1.0
 */
public class Producer {
    public static void main(String[] args) throws Exception {
        //连接
        ConnectionFactory f = new ConnectionFactory();
        f.setHost("192.168.64.140");
        f.setUsername("admin");
        f.setPassword("admin");
        Connection connection = f.newConnection();
        Channel c = connection.createChannel();
        //定义交换机
        c.exchangeDeclare("direct_logs", BuiltinExchangeType.DIRECT);

        //向交换机发送信息 并携带路由键关键词
        while(true){
            System.out.println("输入信息:");
            String s = new Scanner(System.in).nextLine();
            System.out.println("输入路由键: ");
            String key=new Scanner(System.in).nextLine();
            c.basicPublish("direct_logs",key,null,s.getBytes());
        }
    }

}
